﻿using Autodesk.AutoCAD.Runtime;

namespace DYH.Extensions.CAD.Tools.Cad;

/// <summary>
/// RXClass工具
/// </summary>
public static class RxClassTool
{
    /// <summary>
    /// 获取RXClass
    /// </summary>
    /// <typeparam name="T">类型</typeparam>
    /// <returns>RXClass</returns>
    public static RXClass Get<T>() where T : DBObject
    {
        var type = typeof(T);
        if (!_rxClassDic.TryGetValue(type, out var rxClass))
        {
            rxClass = _rxClassDic[type] = RXObject.GetClass(type);
        }

        return rxClass;
    }

    /// <summary>
    /// 内部字典，防止每次创建RXClass速度过慢的问题
    /// </summary>
    private static readonly Dictionary<Type, RXClass> _rxClassDic = [];
}